<template>
  <view>
	  <view class="fanhui2" @tap="back2">返回</view>
	<!-- <text style="width:1px;font-size: 5px;">返回</text> -->
    <canvas canvas-id="mansa1" id="mansa1" class="charts" @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend"/>
  </view>
</template>

<script>
import uCharts from '@/uni_modules/qiun-data-charts/js_sdk/u-charts/u-charts.js';
var uChartsInstance = {};
export default {
  data() {
    return {
		unit:[],
		types:[],
		counts:[],
		photostats:[],
		headerUrl:{
			local:'http:/'+'/'+'127.0.0.1:',
			
		},
      cWidth: 750,
      cHeight: 800,
    };
  },
  onReady() {
	this.initReady(); 
    //这里的 750 对应 css .charts 的 width
    this.cWidth = uni.upx2px(750);
    //这里的 500 对应 css .charts 的 height
    this.cHeight = uni.upx2px(500);
    this.getServerData();
	
  },
  methods: {
	  back2(){
		  uni.redirectTo({url:"../index/index"})
	  },
	  //所有井的统计图
	  initReady(){
		  //let url ='9011/app/app/appwellCount'
		  let url =this.$requestUrl.requestUrl('/zs')+'/app/app/appwellCount';
		let data={};
		let that=this;
		//console.log(url);
		this.$api.register(url,data,'GET').then(res => {
				// 成功的操作
				//console.log("ssssssssss");
				this.unit = res.data.orgName;
				let dName = res.data.dictName
				let dList = res.data.dataList
				res.data.dictName
				for (var i = 0; i < dName.length; i++) {
					let ss = {
						name:"",
						data:[]
					}
					
					ss.name = dName[i]
					ss.data = dList[i]
					this.photostats.push(ss)
					
				}
				console.log("ssssssssss");
				console.log(this.photostats);
				
				}).catch(err => {
					console.log("nnnnnnnnn");
				// 失败的操作
				})
	  },
    getServerData() {
      //模拟从服务器获取数据时的延时
      setTimeout(() => {
        //模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
		let res = {
			//categories: this.unit,
            categories: this.unit,
            //series: this.photostats,
			series: this.photostats,
          };
        this.drawCharts('mansa1', res);
      }, 500);
    },
    drawCharts(id,data){
      const ctx = uni.createCanvasContext(id, this);
      uChartsInstance[id] = new uCharts({
        type: "column",
        context: ctx,
        width: this.cWidth,
        height: this.cHeight,
        categories: data.categories,
        series: data.series,
        animation: true,
        timing: "easeOut",
        duration: 1000,
        rotate: false,
        rotateLock: false,
        background: "#FFFFFF",
        color: ["#1890FF","#91CB74","#FAC858","#EE6666","#73C0DE","#3CA272","#FC8452","#9A60B4","#ea7ccc"],
        padding: [15,15,0,5],
        fontSize: 13,
        fontColor: "#666666",
        dataLabel: true,
        dataPointShape: false,
        dataPointShapeType: "solid",
        touchMoveLimit: 60,
        enableScroll: true,
        enableMarkLine: false,
        legend: {
          show: true,
          position: "bottom",
          float: "center",
          padding: 5,
          margin: 5,
          backgroundColor: "rgba(248,25,25,0)",
          borderColor: "rgba(220,37,37,0)",
          borderWidth: 100,
          fontSize: 13,
          fontColor: "#666666",
          lineHeight: 11,
          hiddenColor: "#b9b9b9",
          itemGap: 80
        },
        xAxis: {
          disableGrid: true,
          disabled: false,
          axisLine: true,
          axisLineColor: "#CCCCCC",
          calibration: false,
          fontColor: "#666666",
          fontSize: 13,
          rotateLabel: false,
          rotateAngle: 45,
          itemCount: 5,
          boundaryGap: "center",
          splitNumber: 1,
          gridColor: "#CCCCCC",
          gridType: "solid",
          dashLength: 4,
          gridEval: 5,
          scrollShow: false,
          scrollAlign: "left",
          scrollColor: "#A6A6A6",
          scrollBackgroundColor: "#EFEBEF",
          formatter: ""
        },
        yAxis: {
          data: [
            {
              min: 0,
              titleFontSize: 5,
			  // unit: "口井",//y轴单位
            }
          ],
          disabled: false,
          disableGrid: true,
          splitNumber: 5,
          gridType: "solid",
          dashLength: 8,
          gridColor: "#CCCCCC",
          padding: 100,
          showTitle: false
        },
        extra: {
          column: {
            type: "group",
            width: 30,
            activeBgColor: "#000000",
            activeBgOpacity: 0.08,
            seriesGap: 2,
            categoryGap: 5,
            barBorderCircle: false,
            linearType: "none",
            linearOpacity: 1,
            colorStop: 0,
            meterBorder: 1,
            meterFillColor: "#FFFFFF"
          },
          tooltip: {
            showBox: true,
            showArrow: true,
            showCategory: false,
            borderWidth: 0,
            borderRadius: 0,
            borderColor: "#000000",
            borderOpacity: 0.7,
            bgColor: "#000000",
            bgOpacity: 0.7,
            gridType: "solid",
            dashLength: 4,
            gridColor: "#CCCCCC",
            fontColor: "#FFFFFF",
            splitLine: true,
            horizentalLine: false,
            xAxisLabel: false,
            yAxisLabel: false,
            labelBgColor: "#FFFFFF",
            labelBgOpacity: 0.7,
            labelFontColor: "#666666"
          },
          markLine: {
            type: "solid",
            dashLength: 4,
            data: []
          }
        }
      });
    },
    touchstart(e){
      uChartsInstance[e.target.id].scrollStart(e);
    },
    touchmove(e){
      uChartsInstance[e.target.id].scroll(e);
    },
    touchend(e){
      uChartsInstance[e.target.id].scrollEnd(e);
      uChartsInstance[e.target.id].touchLegend(e);
      uChartsInstance[e.target.id].showToolTip(e);
    }
  }
};
</script>

<style scoped>
  .charts{
    width: 750rpx;
    height: 500rpx;
  }
  .fanhui2{
	  margin-left: 0.2cm;
	  padding-top:0px;
	  width:50px;
	  height: 50px;
	  font-size: 8px;
	  color: #ffaa7f;
  }
</style>